<?php
/**
 * Lang.php		local
 *
 * @package		
 * @Copyright	(c) All rights reserved
 * @Author		skyCrack <skyCrack@126.com>
 * @Version		$Id$
 */

require_once 'Context.php';

class Lang {
	private static $lang		=	array();
	private $baseDir			=	'';
	private $charSet			=	'';
	
	public function __construct($baseDir, $defLang = 'zh_CN') {
		$this->baseDir	=	$baseDir;
		$this->charSet	=	$defLang;
	}
			
	public function setLocal($lang) {
		$this->charSet	=	$lang;
	}
	
	public function getLang() {
		return self::$lang;
	}
	
	public function getLocal() {
		if ( isset($_COOKIE['locale']) ) {
			$lang	=	$_COOKIE['locale'];
		} elseif ( isset($_SESSION['locale']) ) {
			$lang	=	$_SESSION['locale'];
		} else {
			$lang	=	'zh_CN';
		}
		
		return $lang;
	}
	
	public function load($file) {
		include_once $this->baseDir . '/' . $this->charSet . '/' . $file . '.php';
		self::$lang		=	array_merge(self::$lang, $_sysMsg);
	}
	
	
	private function getBrowseLang() {
		if ( $charSet = getenv('HTTP_ACCEPT_LANGUAGE'))
			return $charSet;
	}
	
	public function bindDomain($domain, $directory) {
	}
	
	public static function get($key, $msg = '') {
		if ( isset(self::$lang[$key]) ) {
			return sprintf(self::$lang[$key], $msg);
		} else {
			return $key;
		}
	}
}
?>